package com.downguys.controller;

import com.downguys.domain.OauthAccessToken_copy;
import com.downguys.domain.OauthParam;
import com.downguys.domain.paramobjects.LoginObj;
import com.downguys.domain.paramobjects.OauthAndClientInfoObj;
import com.downguys.result.ReturnResult;
import org.apache.log4j.Logger;
import org.jsondoc.core.annotation.*;
import org.jsondoc.core.pojo.ApiStage;
import org.jsondoc.core.pojo.ApiVisibility;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 登录服务
 *
 * @author xiyang.qiao
 * @date 2017/1/3 - 21:01
 */
@Api(name = "LoginController", description = "login 登录服务", group = "user", visibility = ApiVisibility.PUBLIC, stage = ApiStage.RC)
@ApiVersion(since = "1.0.0", until = "--")
@Controller
@RequestMapping(value = "api/login")
public class LoginController {

    public static final Logger logger = Logger.getLogger(LoginController.class);


    /**
     * 通过账号名密码登录
     *
     * @author xiyang.qiao
     * @date 2017/1/3 - 21:00
     */
    @ApiMethod(path = "/password",description = "账号密码登录",produces = {MediaType.ALL_VALUE})
    @RequestMapping(value = "/password", method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult loginPassword(@RequestBody @ApiBodyObject LoginObj loginObject){

        ReturnResult returnResult = new ReturnResult();
        returnResult.setResult(new OauthAccessToken_copy());

        return returnResult;
    }

    /**
     * 通过userId直接登录
     *
     * @author xiyang.qiao
     * @date 2017/1/3 - 21:00
     */
    @ApiMethod(path = "/{userId}",description = "通过userId直接登录，用于验证码登录的场景",produces = {MediaType.ALL_VALUE})
    @RequestMapping(value = "/{userId}", method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult loginUserId(
            @RequestBody @ApiBodyObject OauthAndClientInfoObj oauthAndClientInfo,
            @ApiPathParam(description = "userId",name = "userId")
            @PathVariable(name = "userId",required = true) int userId ){

        ReturnResult returnResult = new ReturnResult();
        returnResult.setResult(new OauthAccessToken_copy());

        return returnResult;
    }


    /**
     * 校验登录状态，token是否合法，用户是否在登录状态
     *
     * @author xiyang.qiao
     * @date 2017/1/3 - 21:00
     */
    @ApiMethod(path = "/checkPermission",description = "校验登录状态，token是否合法，用户是否在登录状态",produces = {MediaType.ALL_VALUE})
    @RequestMapping(value = "/checkPermission", method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult checkPermission(
            @RequestBody @ApiBodyObject OauthParam oauthParam,
            @ApiQueryParam(description = "accessToken",name = "accessToken")
            @RequestParam(name = "accessToken",required = true) String accessToken){

        ReturnResult returnResult = new ReturnResult();
        returnResult.setResult(new OauthAccessToken_copy());

        return returnResult;
    }

}
